package com.campusmarket.service;

import com.campusmarket.common.base.BaseService;
import com.campusmarket.dto.CommodityDto;
import com.campusmarket.dto.LayuiDataGridResult;
import com.campusmarket.mapper.CommodityMapper;
import com.campusmarket.model.Commodity;
import com.campusmarket.model.User;
import com.sun.org.apache.regexp.internal.RE;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CommodityService  extends BaseService<Commodity>{

    @Autowired
    private CommodityMapper commodityMapper;

    public LayuiDataGridResult selectListByPage(int page, int limit, String key, User user) {
        LayuiDataGridResult result=new LayuiDataGridResult();
        Integer count=commodityMapper.selectCount();
        List<CommodityDto> list;
        if(user!=null){
            list=commodityMapper.selectList(page-1,limit,key,user.getId());
        }else{
            list=commodityMapper.selectList(page-1,limit,key,null);
        }
        result.setCount((long)count);
        result.setData(list);
        return result;
    }



   /* public boolean add_commodity(Commodity commodity){
        try{
            log.info("增加商品信息");
            commodityMapper.insert(commodity);
        }catch(Exception e){
            //增加失败
            return false;
        }
        return true;
    }

    public boolean del_commodity(Long id){
        try{
            log.info("删除商品信息");
            commodityMapper.deleteByPrimaryKey(id);
        }catch(Exception e){
            //删除失败
            return false;
        }
        return true;
    }

    public boolean query_commodity(Long id){
        try{
            log.info("查看商品信息");
            commodityMapper.selectByPrimaryKey(id);
        }catch(Exception e){
            //无法查看
            return false;
        }
        return true;
    }

    public boolean update_commodity(Commodity commodity){
        try{
            log.info("修改商品信息");
            commodityMapper.updateByPrimaryKey(commodity);
        }catch(Exception e){
            //修改失败
            return false;
        }
        return true;
    }*/

}
